Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports Csla
Imports Csla.Data

<Serializable()> _
Public Class rw_divisionChildList
    Inherits Csla.BusinessListBase(Of rw_divisionChildList, rw_divisionChild)

#Region " BindingList Overrides "

    Protected Overrides Function AddNewCore() As Object
        Dim item As rw_divisionChild = rw_divisionChild.NewDivisionChild()
        Me.Add(item)
        Return item
    End Function

#End Region ' BindingList Overrides

#Region " Factory Methods "

    Friend Shared Function Newrw_divisionChildList() As rw_divisionChildList
        Return New rw_divisionChildList()
    End Function

    Friend Shared Function Getrw_divisionChildList(ByVal dr As SafeDataReader) As rw_divisionChildList
        Return New rw_divisionChildList(dr)
    End Function

    Private Sub New()
        MarkAsChild()
    End Sub

    Private Sub New(ByVal dr As SafeDataReader)
        MarkAsChild()
        Fetch(dr)
    End Sub

#End Region ' Factory Methods

#Region " Data Access "

    Private Sub Fetch(ByVal dr As SafeDataReader)
        RaiseListChangedEvents = False

        While dr.Read()
            Me.Add(rw_divisionChild.GetDivisionChild(dr))
        End While

        RaiseListChangedEvents = True
    End Sub

    Friend Sub Update(ByVal cn As SqlConnection, ByVal parent As rw_leagueRoot)
        RaiseListChangedEvents = False

        ' loop through each deleted child object
        For Each deletedChild As rw_divisionChild In DeletedList
            deletedChild.DeleteSelf(cn)
        Next
        DeletedList.Clear()

        ' loop through each non-deleted child object
        For Each child As rw_divisionChild In Me
            If child.IsNew Then
                child.Insert(cn, parent)
            Else
                child.Update(cn, parent)
            End If
        Next

        RaiseListChangedEvents = True
    End Sub

#End Region ' Data Access

End Class
